package com.city.service.supervise.impl;

import com.city.domain.supervise.PubKeyPerson;
import com.city.repository.pub.PubKeyPersonRepository;
import com.city.service.supervise.PubKeyPersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @deprecation:
 * @dmail: 398521613@qq.com
 * @author: L-H
 * @date: 2018-07-26 12:36
 */
@Service
public class PubKeyPersonServiceImpl implements PubKeyPersonService {

    @Autowired
    private PubKeyPersonRepository keyPersonRepository;

    @Override
    public List<PubKeyPerson> getKeyPersonLimit(Integer limitPage, Integer limitNum, Integer status) {
        return keyPersonRepository.getKeyPersonLimit((limitPage - 1) * limitNum, limitNum, status);
    }

    @Override
    public List<PubKeyPerson> getKeyPersonLimit(Integer limitPage, Integer limitNum, Integer status, String search) {
        return keyPersonRepository.getKeyPersonLimit((limitPage - 1) * limitNum, limitNum, status, search);
    }

    @Override
    public List<PubKeyPerson> findAll(PubKeyPerson pubKeyPerson) {
        //创建匹配器，即如何使用查询条件
        ExampleMatcher matcher = ExampleMatcher.matching() //构建对象
                .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains())
                .withMatcher("reason", ExampleMatcher.GenericPropertyMatchers.contains())
                .withMatcher("now_situation", ExampleMatcher.GenericPropertyMatchers.contains()); //“模糊查询”的方式查询

        //创建实例
        Example<PubKeyPerson> ex = Example.of(pubKeyPerson, matcher);

        //查询
        return keyPersonRepository.findAll(ex);
    }

    @Override
    public Long count(PubKeyPerson pubKeyPerson) {
        //创建匹配器，即如何使用查询条件
        ExampleMatcher matcher = ExampleMatcher.matching() //构建对象
                .withMatcher("name", ExampleMatcher.GenericPropertyMatchers.contains())
                .withMatcher("reason", ExampleMatcher.GenericPropertyMatchers.contains())
                .withMatcher("now_situation", ExampleMatcher.GenericPropertyMatchers.contains()); //“模糊查询”的方式查询

        //创建实例
        Example<PubKeyPerson> ex = Example.of(pubKeyPerson, matcher);

        //查询
        return keyPersonRepository.count(ex);
    }

    @Override
    public PubKeyPerson findById(Integer id) {
        return keyPersonRepository.findById(id);
    }

    @Override
    public PubKeyPerson findByName(String name) {
        return keyPersonRepository.findByName(name);
    }
}
